﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XrmLibrary.Configurations;

namespace XrmLibrary.ConfigFile
{
    public class AdapterInstanceConverter
    {
        private AdapterInstanceCollection _adapterInstance;

        private AdapterInstanceConverter(AdapterInstanceCollection adapterInstance)
        {
            _adapterInstance = adapterInstance;
        }

        public static AdapterInstanceConverter Instantiate(AdapterInstanceCollection adapterInstance)
        {
            return new AdapterInstanceConverter(adapterInstance);
        }

        public AdapterConfiguration GetDynamicAdapterConfiguration()
        {
            DynamicInstanceConfiguration dynamicInstanceConfig = DynamicInstanceConfiguration.Instantiate(_adapterInstance.Name);
            foreach(AdapterInstance kvp in _adapterInstance)
            {
                dynamicInstanceConfig.Add(kvp.Key, kvp.Value);
            }
            AdapterConfiguration adapterConfig = new AdapterConfiguration(dynamicInstanceConfig);
            return adapterConfig;
        }
    }
}
